package com.gxuwz.util;

import org.apache.log4j.Logger;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;

/**
 * 全局常量配置
 * @version 1.0
 */
public class SystemContext {
	
	private final static Logger log = Logger.getLogger(SystemContext.class);
	
	private static final String SITE_WIDE_SECRET = "timo_7758_key";  
	private static final PasswordEncoder encoder = new StandardPasswordEncoder(SITE_WIDE_SECRET); 
	public static final String IMG ="/upload/images/"; //图片上传目录
	public static final String USER_FACE = "/images/userface1.jpg";
	/**
	 * 密码加密
	 * @param rawPasswd 需要加密的密码
	 * @return
	 */
	public static String passwdEncryption(String rawPasswd){
		//System.out.println("rawPasswd="+rawPasswd);
		String str = encoder.encode(rawPasswd);
		return str;
	}

	/**
	 * 密码校验
	 * @param rawPassword 明文密码（需要匹配的用户输入的那份）
	 * @param password 数据库保存的加密的密码
	 * @return true = 通过，fasle=失败
	 */
	public static boolean passwdDecryption(String rawPasswd, String password){
		boolean isT = false;
		try {
			isT = encoder.matches(rawPasswd, password);
//			log.info("密码匹配："+rawPasswd+"    "+password);
		} catch (Exception e) {
			log.error("密码匹配："+e);
		}
		return isT;
	}
}
